package ontology.concepts.vo;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import ontology.concepts.general.IOutcome;

@Entity
@NamedQueries(
		{
			@NamedQuery(name = "VOCase.findVOOutcomeByVOCase", query = "SELECT o from VOOutcome o WHERE o.problem.id = :caseId"),
		}
)
public class VOOutcome implements IOutcome<Integer>{

	@Id
	@GeneratedValue
	private Integer ID;
	
	@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	private VOCase problem;
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	private Set<VOObligation> obligations;

	@Override
	public Integer getID() {
		return ID;
	}

	@Override
	public void setID(Integer iD) {
		ID = iD;		
	}

	public VOCase getProblem() {
		return problem;
	}

	public void setProblem(VOCase problem) {
		this.problem = problem;
	}

	public Set<VOObligation> getObligations() {
		return obligations;
	}

	public void setObligations(Set<VOObligation> obligations) {
		this.obligations = obligations;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((ID == null) ? 0 : ID.hashCode());
		result = prime * result
				+ ((obligations == null) ? 0 : obligations.hashCode());
		result = prime * result + ((problem == null) ? 0 : problem.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		VOOutcome other = (VOOutcome) obj;
		if (ID == null) {
			if (other.ID != null)
				return false;
		} else if (!ID.equals(other.ID))
			return false;
		if (obligations == null) {
			if (other.obligations != null)
				return false;
		} else if (!obligations.equals(other.obligations))
			return false;
		if (problem == null) {
			if (other.problem != null)
				return false;
		} else if (!problem.equals(other.problem))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "VOOutcome [ID=" + ID + ", problem=" + problem
				+ ", obligations=" + obligations + "]";
	}		
}
